<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('入职申请列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>


                            <li class="select-time">
                                <p>申请时间：</p>
                                <input type="text" class="time-input" id="startTime" placeholder="开始时间" name="params[beginTime]"/>
                                <span>-</span>
                                <input type="text" class="time-input" id="endTime" placeholder="结束时间" name="params[endTime]"/>
                            </li>

                            <li>
                                <label>员工姓名：</label>
                                <input type="text" name="empName"/>
                            </li>

                            <div th:include="include/deptSearch::deptSearch"></div>

                            <li>
                                <p>状态：</p>
                                <select name="auditStatus" th:with="type=${@dict.getType('auditStatus')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>

                            <!--  <li>
                                  <label>offer接收人邮箱：</label>
                                  <input type="text" name="toOffEmail"/>
                              </li>-->
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">

                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="hr:manager:export">
                    <i class="fa fa-download"></i> 导出
                </a>

            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>


     <div class="container-div" id="hiddenDiv" hidden="hidden">
         <div class="row">
             <form class="form-horizontal m" id="form-toolRepeal">
                 <div class="btn-group-sm" id="toolRepeal" >
                     <div class="form-group">
                         <input name="instanceId" id="instanceId" class="form-control" type="hidden">
                         <label class="col-sm-3 control-label is-required">撤回理由：</label>
                         <div class="col-sm-8">
                             <input name="message" class="form-control" type="text" required>
                         </div>
                     </div>
                 </div>
             </form>
         </div>
     </div>


    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('hr:manager:edit')}]];
        var removeFlag = [[${@permission.hasPermi('hr:manager:remove')}]];
        var sexDatas = [[${@dict.getType('sys_user_sex')}]];
        var citys = [[${@dict.getType('citys')}]];
        var recruitEducationDatas = [[${@dict.getType('sys_education')}]];
        var prefix = ctx + "hr/manager";
        var currentUser = [[${currentUser}]];

        var recruitDeptAllDatas = [[${@deptService.getDeptAll()}]];
        var recruitPostAllDatas = [[${@postService.getPostAll()}]];
        /* 查看审批历史 */
        function showHistoryDialog(instanceId) {
            var url = ctx + 'process/general/historyList/' + instanceId;
            $.modal.open("查看审批历史", url);
        }

        function showProcessImgDialog(instanceId) {
            var url = ctx + 'process/general/processImg/' + instanceId;
            $.modal.open("查看流程图 (标红表示已结束或活动中的流程)", url);
        }

        function repeal(instanceId,createBy){
            if (createBy !== currentUser.loginName) {
                $.modal.alertWarning("不允许非创建人撤回表单！");
                return;
            }
            var url = prefix + "/repeal";
            $('#instanceId').val(instanceId);
            layer.open({
                type: 1,
                area: ['600px', '300px'],
                fix: false,
                //不固定
                maxmin: true,
                shade: 0.3,
                title: "撤销申请",
                content: $('#hiddenDiv'),
                btn: ['确定', '关闭'],
                // 弹层外区域关闭
                shadeClose: false,
                yes: function(index) {
                    if ($.validate.form('form-toolRepeal')) {
                        $.operate.save(url, $('#form-toolRepeal').serialize());
                    }
                }
            });

        }

        $(function() {
            var options = {
                url: prefix + "/listManage",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                detailUrl: prefix + "/detail/{id}",
                modalName: "入职申请",
                uniqueId: "id",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'id',
                    title: '入职申请id',
                    visible: false
                },
                {
                    field: 'empName',
                    title: '入职员工'
                },
                {
                    field: 'nonManagerDate', 
                    title: '入职日期'
                },
                {
                    field: 'nonManagerDeptId',
                    title: '入职部门',
                    formatter: function(value, row, index) {
                        return $.table.selectDeptLabel(recruitDeptAllDatas, value);
                    }
                },
                {
                    field: 'nonManagerPostId', 
                    title: '入职岗位',
                    formatter: function(value, row, index) {
                        return $.table.selectPostLabel(recruitPostAllDatas, value);
                    }
                },
                {
                    field: 'citys',
                    title: '入职城市',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(citys, value);
                    }
                },
                {
                    field: 'todoUserName',
                    title: '当前处理人'
                },
                {
                    field: 'auditStatus',
                    title: '审核状态',
                    formatter: function(value, row, index) {
                        //0：待审核，1：审核中，2：通过，3：未通过
                        if (value == 0){
                            return '待提交';
                        }
                        if (value == 1){
                            return '审核中';
                        }
                        if (value == 2){
                            return '通过';
                        }
                        if (value == 4){
                            return '撤销';
                        }
                        return '拒绝';
                    }
                },
                {
                    field: 'createBy',
                    title: '创建人ID',
                    visible: false
                },
                {
                    field: 'createUserName',
                    title: '创建人',
                    visible: false
                },{
                        field: 'applyTime',
                        title: '申请时间'
                    },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.detail(\'' + row.id + '\')"><i class="fa fa-edit"></i>详情</a> ');
                        actions.push('<a class="btn btn-warning btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="showHistoryDialog(\'' + row.instanceId + '\')"><i class="fa fa-list"></i> 审批历史</a> ');
                        actions.push('<a class="btn btn-info btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="showProcessImgDialog(\'' + row.instanceId + '\')"><i class="fa fa-image"></i> 进度查看</a> ');
                        if (row.delFlag == 0 && row.status == "0" && row.auditStatus == 0){
                            // actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="commit(\'' + row.id + '\',\'' + row.createBy + '\')"><i class="fa fa-edit"></i>提交</a>');
                        }

                        if (row.delFlag == 0 && row.auditStatus < 2 && row.status == "1"){
                            // actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="repeal(\'' + row.instanceId + '\',\'' + row.createBy + '\')"><i class="fa fa-remove"></i>撤回</a>');
                        }

                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);

        });

        function addNonManager() {
            $.operate.openDiv("入职申请" ,  prefix + "/add",1500);
        }


        function commit(id,createBy){
            if (createBy !== currentUser.loginName) {
                $.modal.alertWarning("不允许非创建人提交申请！");
                return;
            }
            var url = prefix + "/commit?id="+id;
            $.ajax({
                url: url,
                cache: false,
                contentType: false,
                processData: false,
                type: 'POST',
                success: function (result) {
                    if (result.code == web_status.SUCCESS) {
                        $.modal.closeAll();
                        $.modal.alertSuccess(result.msg);
                        $.table.refresh();
                    } else if (result.code == web_status.WARNING) {
                        layer.close(index);
                        $.modal.enable();
                        $.modal.alertWarning(result.msg)
                    } else {
                        layer.close(index);
                        $.modal.enable();
                        $.modal.alertError(result.msg);
                    }
                }
            });

        }
    </script>
</body>
</html>